import type { Tree } from "@/myType"
import type { RouteRecordName, RouteRecordRaw } from "vue-router"

const menu: Tree[] = [
    {
        menuid: "0-0",
        path: '/home',
        name: 'home',
        meta: {
            title: '系统首页'
        },
        component: () => import('../views/BannerView.vue'),
    },
    {
        menuid: "0-1",  
        path: '/banner',
        name: 'banner',
        meta: {
            title: '轮播图管理'
        },
        children: [
            {
                menuid: "0-1-0",
                path: '/banner/list',
                name: 'bannerlist',
                meta: {
                    title: '轮播图列表'
                },
                component: () => import('../views/BannerView.vue'),
            },
            // {
            //     menuid: "0-1-1",
            //     label: '添加轮播图',
            // },
        ],
    },
    {
        menuid: "0-2",
        path: '/pro',
        name: 'pro',
        meta: {
            title: '产品管理'
        },
        children: [
            {
                menuid: "0-2-0",
                name: 'prolist',
                path: '/pro/list',
                component: () => import('../views/Product/ListView.vue'),
                meta: {
                    title: '产品列表'
                }
            },
            {
                menuid: "0-2-1",
                path: '/pro/seckill',
                name: 'proseckill',
                component: () => import('../views/Product/SecKillView.vue'),
                meta: {
                    title: '秒杀列表'
                }
            },
            {
                menuid: "0-2-2",
                path: '/pro/recommend',
                name: 'prorecommend',
                component: () => import('../views/Product/RecommendView.vue'),
                meta: {
                    title: '推荐列表'
                }
            },
            {
                menuid: "0-2-3",
                path: '/pro/search',
                name: 'prosearch',
                component: () => import('../views/Product/SearchView.vue'),
                meta: {
                    title: '筛选列表'
                }
            },

        ],
    },
    {
        menuid: "0-3",
        path: '/user',
        name: 'user',
        meta: {
            title: '账户管理'
        },
        children: [
            {
                menuid: "0-3-0",
                path: '/user/list',
                name: 'userlist',
                meta: {
                    title: '用户列表'
                },
                icon: '<Expand/>',
                component: () => import('../views/Account/UserListView.vue'),
            },
            {
                menuid: "0-3-1",
                path: '/user/managers',
                name: 'usermanagers',
                meta: {
                    title: '管理员列表'
                },
                component: () => import('../views/Account/ManagersView.vue'),
            }
        ],
    },
    // {
    //     menuid: '0-4',
    //     label: '设置'
    // },
    // {
    //     menuid: "0-5",
    //     label: '数据可视化',
    //     children: [
    //         {
    //             menuid: "0-5-0",
    //             label: 'echarts使用示例',
    //         },
    //         {
    //             menuid: "0-5-1",
    //             label: 'antv-g2使用示例',
    //         },
    //         {
    //             menuid: "0-5-2",
    //             label: 'antdcharts',
    //         }
    //     ],
    // },
    // {
    //     menuid: "0-6",
    //     label: '编辑器',
    //     children: [
    //         {
    //             menuid: "0-6-0",
    //             label: '富文本编辑器',
    //         },
    //         {
    //             menuid: "0-6-1",
    //             label: 'markdown编辑器',
    //         }
    //     ],
    // },
    // {
    //     menuid: "0-7",
    //     label: '导入以及导出',
    //     children: [
    //         {
    //             menuid: "0-7-0",
    //             label: '导入excel',
    //         },
    //         {
    //             menuid: "0-7-1",
    //             label: '导出excel',
    //         }
    //     ],
    // },
    // {
    //     menuid: "0-8",
    //     label: '地图使用',
    //     children: [
    //         {
    //             menuid: "0-8-0",
    //             label: '百度地图',
    //         },
    //         {
    //             menuid: "0-8-1",
    //             label: '高德地图',
    //         },
    //         {
    //             menuid: "0-8-2",
    //             label: '腾讯地图',
    //         }
    //     ],
    // },
    // {
    //     menuid: '0-9',
    //     label: '客服'
    // }
]

export const getGrantsFn = (grants: any, role: any, router: any, menus: Tree[] = menu) => {
    if (role == '2') {
        grants = ["0-0", "0-1", "0-1-0", "0-1-1", "0-2", "0-2-0", "0-2-1", "0-2-2", "0-3", "0-3-0", "0-3-1"]
        // return menus
    }
    let arr: Tree[] = []
    menus.forEach(item => {
        if (grants.includes(item.menuid)) {
            arr.push({ ...item })
            if (item.children) {
                arr[arr.length - 1].children = new Array()
                item.children.forEach(subItem => {

                    if (grants.includes(subItem.menuid)) {
                        arr[arr.length - 1].children?.push({ ...subItem });
                        router.addRoute('admin', subItem);
                    }
                })
            } else {
                router.addRoute('admin', item);
            }

        }
    })
    console.log('看这个---->', router.getRoutes())

    return arr
}